//
//  ViewController.m
//  GradientLabel
//
//  Created by 万孟超 on 2022/1/19.
//

#import "ViewController.h"
#import "UIGradientLabel.h"
#import "UIImage+Gradient.h"

#define COLOR_RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define COLOR_RGB(r,g,b) COLOR_RGBA(r,g,b,1.0f)
#define COLOR_HEX(hex) COLOR_HEXA(hex,1.0f)
#define COLOR_HEXA(rgbValue,a) [UIColor colorWithRed:((float)(((rgbValue) & 0xFF0000) >> 16))/255.0 green:((float)(((rgbValue) & 0xFF00)>>8))/255.0 blue: ((float)((rgbValue) & 0xFF))/255.0 alpha:(a)]
#define COLOR_RANDOM [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createLabel];
}

- (void)createLabel {
    UIImage *image = [UIImage gradientColorImageFromColors:@[COLOR_HEX(0xE08CFF),COLOR_HEX(0x0FC8FF)] gradientType:UIImageGradientTypeUpleftToLowright imgSize:self.view.frame.size];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = self.view.frame;
    [self.view addSubview:imageView];
    UIGradientLabel *label = ({
        UIGradientLabel *label = [[UIGradientLabel alloc] initWithFrame:CGRectMake(100, 300, self.view.frame.size.width - 200, 60)];
        label.text = @"文字开始渐变背景颜色扫描";
        
        //这个设置无效，和numberOfLines冲突
        label.lineBreakMode = NSLineBreakByWordWrapping;
        
        label.textAlignment = NSTextAlignmentCenter;
        label.numberOfLines = 0;
        label.font = [UIFont systemFontOfSize:18];
        label.textColor = COLOR_HEX(0x3EFF32);
        label.gradientColor =
        @[label.textColor, label.textColor,
          COLOR_HEX(0xFF2E27), COLOR_HEX(0xFC1AFF),
          label.textColor, label.textColor];
        label;
    });
    [self.view addSubview:label];
}



@end
